package com.gin.supermarket_inventory_system.inventory.dto.vo;

import com.gin.database.base.BaseVo;
import com.gin.supermarket_inventory_system.inventory.entity.SettlementDayPo;
import com.gin.supermarket_inventory_system.inventory.entity.SettlementMonthPo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 结算
 * @since : 2023/10/16 17:30
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "视图对象:结算")
public class SettlementVo extends BaseVo {
    @Schema(description = "日期")
    String date;

    @Schema(description = "销售收入总额")
    double totalPriceSell;

    @Schema(description = "销售单数")
    int countSell;

    @Schema(description = "销售退货总额")
    double totalPriceCancel;

    @Schema(description = "销售退货单数")
    int countCancel;

    @Schema(description = "进货总额")
    double totalPricePurchase;

    @Schema(description = "进货单数")
    int countPurchase;

    @Schema(description = "退货总额")
    double totalPriceReject;

    @Schema(description = "退货单数")
    int countReject;

    public SettlementVo(SettlementDayPo po) {
        // 复制Po的字段
        BeanUtils.copyProperties(po, this);
    }

    public SettlementVo(SettlementMonthPo po) {
        // 复制Po的字段
        BeanUtils.copyProperties(po, this);
    }

    /**
     * 将持久对象列表转换为视图对象列表
     * @param data 持久对象列表
     * @return 视图对象列表
     */
    public static List<SettlementVo> toVoList(List<SettlementDayPo> data) {
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(SettlementVo::new).toList();
    }
}
